package com.ibuonline.b2b.member.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.dimeng.common.base.SuperDAO;
import com.ibuonline.b2b.entity.MemberLog;

public class MemberLogDAO extends SuperDAO<MemberLog> {
	
	@SuppressWarnings("unchecked")
	public MemberLog getlastLoginMemberLogById(final Integer memberId) {
		List<MemberLog> list = template.executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session) throws HibernateException, SQLException {
				String hql = "from MemberLog ml where ml.memberId = ? and ml.operation = 'login' order by ml.logTime desc";
				Query query = session.createQuery(hql);
				query.setInteger(0, memberId);
				query.setFirstResult(0);
				query.setMaxResults(1);
				return query.list();
			}
		});
		return (list.size() > 0) ? list.get(0) : null;
	}
}
